package main

import (
	"fmt"
	"io"
	"net"
)

func main() {
	conn, err := net.Dial("tcp", "www.baidu.com:80")
	if err != nil {
		fmt.Println("dial fail...", err.Error())
		return
	}
	defer conn.Close()
	msg := "GET / HTTP/1.1\n"
	msg += "Host: www.baidu.com\r\n"
	msg += "Connection: close\r\n"
	msg += "\r\n\r\n"
	_, err1 := io.WriteString(conn, msg)
	if err1 != nil {
		fmt.Println("打开失败", err1)
		return
	}
	buf := make([]byte, 1024)
	for {
		count, er := conn.Read(buf)
		if er != nil {
			break
		}
		fmt.Println(string(buf[0:count]))
	}
}
